package com.zengdada.authority.annotation;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zengdada.authority.config.security.intercept.AuthorityUtil;
import com.zengdada.authority.model.SysFunkLog;
import com.zengdada.authority.service.ServiceFunkLogAuthorityService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


/**
 * @author zengshunan
 */
@Aspect
@Component
public class SysLogAop extends BaseLogAop<SysLog> {
    static ObjectMapper objectMapper  = new ObjectMapper();

    @Autowired
    @Qualifier("serviceFunkLogAuthorityServiceImpl")
    ServiceFunkLogAuthorityService logService;


    @Autowired
    AuthorityUtil authorityUtil;

    @Value("${authority.application.id}")
    private String applicationId;

    /**
     * 这个里面需要写自定义注解的全限定名（包名+类名）
     *
     * @author zsa
     * @date 2020/9/3 15:07
     */
    @Pointcut("@annotation(com.zengdada.authority.annotation.SysLog)")
    public void logPointCut() {

    }

    @Around("logPointCut()")
    public Object around(ProceedingJoinPoint pjp) {
        return super.analysis(pjp);
    }

    @Override
    protected void setAnnotationMsg(SysLog annotation, SysFunkLog log) {
        log.setType(annotation.type().name());
        log.setRemark("".equals(annotation.value()) ? annotation.remark() : annotation.value());
    }
}
